home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / LASERGNU < prev    next >
Text File  |  1992-03-25  |  4KB  |  164 lines

  1. #!/bin/csh -f
  2. #
  3. # $Id: lasergnu,v 3.26 92/03/24 22:37:01 woo Exp Locker: woo $
  4. #
  5. #
  6. # Print gnuplot output on an Imagen or Postscript laser printer.
  7.  
  8. set print_banner = on    # Print a banner page unless told otherwise.
  9. set input_files = ()    # the plot input command files
  10. set lpr_opts = ()        # options to lpr
  11.  
  12. # Default printer set by shell variable PRINTER.
  13. if (! $?PRINTER) then 
  14.     if ($?LASER) then
  15.           set PRINTER=$LASER
  16.     else
  17.            set PRINTER="lw0"
  18.     endif
  19. endif
  20. set printer = (-P$PRINTER)
  21.  
  22. # File for plot commands, and for plot output
  23. set TMP=/tmp/plot$$
  24. set outfile=$TMP.out    # the output file
  25. onintr cleanup
  26.  
  27. # default is Imagen mode for Imagen printer; see -p option
  28. set setterm="set terminal imagen"
  29. set LANG="-Limpress"
  30.  
  31. set usage="usage: lasergnu [-Pprinter] [-b] [-p] [-t title] [-f file] ['plot command']...."
  32.  
  33. # Loop through the command-line arguments.
  34.  
  35. top:
  36.     if ($#argv > 0) then
  37.  
  38.         switch ("$argv[1]")
  39.  
  40.         case -b*:    # Do not print a banner page.
  41.         case -J*:    # Compatible with imprint.
  42.             set print_banner = off
  43.                      set lpr_opts=($lpr_opts -h)
  44.             shift argv
  45.             goto top
  46.  
  47.         case -f?*:    # Specify file containing plot commands
  48.             set input_files = ($input_files `echo $argv[1] | sed 's/^-f//'`)
  49.             shift argv
  50.             goto top
  51.  
  52.         case -f:    # Specify file containing plot commands
  53.             shift argv
  54.             if ($#argv > 0) then
  55.                 set input_files = ($input_files $argv[1])
  56.                 shift argv
  57.             else
  58.                 echo "Usage: -f file ..."
  59.                 echo "Type    lasergnu -help    for help."
  60.                 exit (1)
  61.             endif
  62.             goto top
  63.  
  64.         case -t?*:    # Specify title of plot
  65.             echo set title \""`echo $argv[1] | sed 's/^-t//'`"\" >> $TMP
  66.             shift argv
  67.             goto top
  68.  
  69.         case -t:    # Specify title of plot
  70.             shift argv
  71.             if ($#argv > 0) then
  72.                 echo set title \""$1"\" >> $TMP
  73.                 shift argv
  74.             else
  75.                 echo "Usage: -t title ..."
  76.                 echo "Type    lasergnu -help    for help."
  77.                 exit (1)
  78.             endif
  79.             goto top
  80.           case -help:
  81.             echo "$usage"
  82.             exit(1)
  83.  
  84.         case -P?*:    # Set the printer, exactly as by itroff.
  85.             set printer = $argv[1]
  86.             shift argv
  87.             goto top
  88.  
  89.         case -P:    # Set the printer, exactly as by itroff.
  90.             shift argv
  91.             if ($#argv > 0) then
  92.                 set printer = (-P$argv[1])
  93.                 shift argv
  94.             else
  95.                 echo "Usage: -P printer ..."
  96.                 echo "Type    lasergnu -help    for help."
  97.                 exit (1)
  98.             endif
  99.             goto top
  100.  
  101.                 # use impress 
  102.            case -I:
  103.                 echo Imagen is the default mode now
  104.              shift argv
  105.                 goto top
  106.  
  107.                 # use postscript instead of impress language
  108.            case -p:
  109.                 set setterm="set term postscript"
  110.                 set LANG="-Lpostscript"
  111.              shift argv
  112.                 goto top
  113.  
  114.         case -?*:
  115.             echo "I do not recognize option $argv[1]."
  116.             echo "$usage"
  117.             exit (1)
  118.  
  119.         default:
  120.               echo "$argv[1]"    >> $TMP
  121.             shift argv
  122.             goto top
  123.  
  124.         endsw
  125.     endif
  126.  
  127. # try to devine the printer type
  128. if ($printer =~ -Plw*) then
  129.     set setterm="set term postscript"
  130.     set LANG="-Lpostscript"
  131. endif
  132.  
  133. if ($printer =~ -Pim*) then
  134.     set setterm="set term imagen"
  135.     set LANG="-Limpress"
  136. endif
  137.  
  138. # Set up input file
  139. echo $setterm > $TMP.plt
  140. echo set output \"$outfile\" >> $TMP.plt
  141. if (-e $TMP) cat $TMP >> $TMP.plt
  142.  
  143. # If input file is specified AND command line contains plot commands, then
  144. #    do command line args first, then plot commands in input file.
  145. gnuplot $TMP.plt $input_files
  146.  
  147. if ($status == 0 && -e $outfile && ! -z $outfile) then
  148.     # The printer is whatever printer was last specified,
  149.     # or the default printer if none was specified.
  150.     if ($LANG == -Limpress) then
  151.         /usr/local/bin/ipr $LANG $printer \
  152.            -D"jobheader $print_banner" \
  153.            -D"pagereversal on" \
  154.            -D"program lasergnu" $outfile
  155.     else if ($LANG == -Lpostscript) then
  156.            lpr $lpr_opts $printer $outfile
  157.     endif
  158. else
  159.     echo "lasergnu: error in plotting or empty plot; nothing printed."
  160. endif
  161.  
  162. cleanup:
  163. rm -f $TMP* $outfile
  164.